﻿using HuaWei.临时目录;
using System;
using System.Threading;

internal class Class40
{
    private static void smethod()
    {
        WaitHandle[] waitHandles = new WaitHandle[] { new ManualResetEvent(false), new ManualResetEvent(false) };
        WaitCallback callBack = new WaitCallback(Class40.smethod1);
        WaitCallback callback2 = new WaitCallback(Class40.smethod2);
        ThreadPool.QueueUserWorkItem(callBack, "第一个线程");
        ThreadPool.QueueUserWorkItem(callBack, "第二个线程");
        MyState state = new MyState("第三个线程", 100, waitHandles[0]);
        ThreadPool.QueueUserWorkItem(callback2, state);
        ThreadPool.QueueUserWorkItem(callback2, new MyState("第四个线程", 2, waitHandles[1]));
        WaitHandle.WaitAll(waitHandles);
        Console.WriteLine("MyState 的 Number 值为: {0}", state.Number);
    }

    public static void smethod1(object _str)
    {
        Console.WriteLine("MyThreadWork 开始启动 …… {0}", _str);
        Thread.Sleep(0x3e8);
        Console.WriteLine("运行结束…… {0}", _str);
    }

    public static void smethod2(object myState)
    {
        MyState state = (MyState)myState;
        Console.WriteLine("MyThreadWork2 开始启动…… {0},{1}", state.Info, state.Number);
        Thread.Sleep(0x3e8);
        MyState state1 = (MyState)myState;
        state1.Number++;
        Console.WriteLine("运行结束…… {0},{1}", state.Info, state.Number);
        ((ManualResetEvent) state.DoneEvent).Set();
    }
}

